#@laybase() 
#define main()
	
	<style>
		#filter{
			margin-bottom:10px;
		}
	
	
		#userManager{
			text-align:center;
			vertical-align:middle;
		}
		#userDetail td{
			text-valign:center;
			vertical-align:middle;
		}
		#userDetail td:last-child>a:nth-child(2){
			margin:0 5px;
		}
		
		
		
		#userIdCardPhoto{
			display:flex;
			width:100%;
			
		}
		#userIdCardPhoto li{
			margin:0 1rem;
		}
		#userIdCardPhoto div{
			width:10rem;
			height:11rem;
			text-align:center;
		}
		#userIdCardPhoto div>img{
			width:100%;
			height:10rem;
		}
	</style>
	
	<form>
		<select  id='filter'>
			<option>-请选择-</option>
			<option value='4'>已通过</option>
			<option value='2'>待审核</option>
			<option value='3'>反馈中</option>
			<option value='1'>已拒绝</option>
		</select>
	</form>
	
	<div class='table-responsive' id='userManager'>
		<table class='table table-bordered' data-toggle="table" data-pagination="true" data-pagesize='15' >
			<thead>
				<tr>
					<th>用户名</th>
					<th>手机号码</th>
					<th>邀请人姓名</th>
					<th>注册时间</th>
					<th>身份证照片</th>
					<th>审核状态</th>
					<th>是否通过审核</th>
				</tr>
			</thead>
			<tbody id='userDetail'>
				
			</tbody>
		</table>
	</div>
		
	<!-- Modal -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">查看照片</h4>
	      </div>
	      <div class="modal-body">
			<ul id='userIdCardPhoto'>
			</ul>
	      </div>
	    </div>
	  </div>
	</div>
	
	<div class="modal fade"  id='userIdCardPhotoModal' tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">照片预览</h4>
	      </div>
	      <div class="modal-body" id='userIdCardPhotoModalPreview'>
	      </div>
	    </div>
	  </div>
	</div>
	
	<div class="modal fade"  id='descMsgModal' tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">反馈内容</h4>
	      </div>
	      <div class="modal-body" id='descMsg'>
	      	<textarea class="form-control" rows="3"></textarea>
	      </div>
	      <div class="modal-footer">
	      	<button class='btn btn-info' id='descBtn' data-dismiss="modal" data-id='' data-progress=''>提交反馈</button>
	      </div>
	    </div>
	  </div>
	</div>
	
	<script>
	
	$(function(){
		
		$.ajax({
			type:'get',
			url:'/admin/reviewUserQuery',
			success:function(data){
				var userDetailHtml='';
				var userIdCardPhotoHtml= '';
				for(var i=0;i<data.length;i++){
					var userName = data[i].userName,
						userPhone = data[i].userPhone,
						refereeName = data[i].refereeName,
						regTime = data[i].regTime,
						idCardPhoto = data[i].idCardPhoto,
						progress = data[i].progress,
						id = data[i].id;
					
					var idCardPhotoArr = idCardPhoto.split(',');
					
					var progressInfo = '';
					if(progress===1){
						progressInfo = '已拒绝' 
					}else if(progress===2){
						progressInfo = '待审核' 
					}else if(progress===3){
						progressInfo = '有反馈' 
					}else{
						progressInfo = '已通过' 
					}
					
					if(regTime===null){
						regTime = '-'
					}
					
				
					userDetailHtml += 	'<tr>'+
											'<td>'+userName+'</td>'+
											'<td>'+userPhone+'</td>'+
											'<td>'+refereeName+'</td>'+
											'<td>'+regTime+'</td>'+
											'<td><a class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-id="'+id+'">查看照片</a></td>'+
											'<td>'+progressInfo+'</td>'+
											'<td>'+
												'<a class="btn btn-success nodesc" data-progress="4" data-nodesc>通过</a>'+
												'<a class="btn btn-danger nodesc" data-progress="1" data-nodesc>拒绝</a>'+
												'<a class="btn btn-warning" data-progress="3" data-toggle="modal" data-target="#descMsgModal" >反馈信息</a>'+
											'</td>'+
										'</tr>';
					
				}
				$('#userDetail').html(userDetailHtml);
			}
		})
		
		$('#userDetail').on('click','a[data-id]',function(){
			var userID = $(this).attr('data-id');
			
			//请求图片
			$.ajax({
				type:'get',
				url:'/admin/reviewUserQuery',
				data:{
					userID:userID
				},
				success:function(data){
					var userIdCardPhotoHtml = '';
					var idCardPhotoArr = data.idCardPhoto.split(',');
					
					for(var r=0;r<idCardPhotoArr.length;r++){

						var idCardPhotoNameStart= idCardPhotoArr[r].lastIndexOf('/');
						var idCardPhotoNameEnd= idCardPhotoArr[r].indexOf('.');
						
						var idCardPhotoName = idCardPhotoArr[r].substring(idCardPhotoNameStart+1,idCardPhotoNameEnd);

						userIdCardPhotoHtml += '<li><div><img src="'+idCardPhotoArr[r]+'" alt="照片读取失败，稍后重试" data-toggle="modal" data-target="#userIdCardPhotoModal" /><span>'+idCardPhotoName+'</span></div></li>'
					}
					$('#userIdCardPhoto').html(userIdCardPhotoHtml);
					
				}
			}) 
			
		})

		//图片预览
		$('#userIdCardPhoto').on('click','img',function(){
			var src = $(this).attr('src');
			var width = $(this)
			var lgImg=$("<div></div>")
			
			lgImg.css({
				width:'500px',
				height:'500px',
				position: "relative"
				
			})
			lgImg.iviewer({
                src: src
           	});
			
			$('#userIdCardPhotoModalPreview').html(lgImg);
			
		})
		
		
		
		//筛选
		$('#filter').change(function(){

			var val = $(this).val();

			$.ajax({
				type:'get',
				url:'/admin/getUserByProgress',
				data:{
					progress:val
				},
				success:function(data){
					var userDetailHtml='';

					for(var i=0;i<data.length;i++){
						var userName = data[i].userName,
							userPhone = data[i].userPhone,
							refereeName = data[i].refereeName,
							regTime = data[i].regTime,
							idCardPhoto = data[i].idCardPhoto,
							progress = data[i].progress,
							id = data[i].id;
						
						var idCardPhotoArr = idCardPhoto.split(',');
						
						var progressInfo = '';
						if(progress===1){
							progressInfo = '已拒绝' 
						}else if(progress===2){
							progressInfo = '待审核' 
						}else if(progress===3){
							progressInfo = '有反馈' 
						}else{
							progressInfo = '已通过' 
						}
						
						if(regTime===null){
							regTime = '-'
						}
						userDetailHtml += 	'<tr>'+
												'<td>'+userName+'</td>'+
												'<td>'+userPhone+'</td>'+
												'<td>'+refereeName+'</td>'+
												'<td>'+regTime+'</td>'+
												'<td><a class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-id="'+id+'">查看照片</a></td>'+
												'<td>'+progressInfo+'</td>'+
												'<td>'+
													'<a class="btn btn-success nodesc" data-progress="4" data-nodesc>通过</a>'+
													'<a class="btn btn-danger nodesc" data-progress="1" data-nodesc>拒绝</a>'+
													'<a class="btn btn-warning" data-progress="3" data-toggle="modal" data-target="#descMsgModal" >反馈信息</a>'+
												'</td>'+
											'</tr>';
						
					}
					$('#userDetail').html(userDetailHtml);
				}
			})
		})
		
		//反馈
		$('#userDetail').on('click','a[data-progress]',function(){
			var progress = $(this).data('progress');
			var userID = $(this).parent().siblings().children('a[data-id]').data('id');
			var msg = '';
			
			$('#descBtn').data('progress',progress);
			$('#descBtn').data('id',userID);
			
			console.log(progress,userID );
			if( $(this).hasClass('nodesc') ){
				$.ajax({
					type:'get',
					url:'/admin/reviewUser',
					data:{
						userID:userID,
						progress:progress
					},
					success:function(data){
						if(data.code == 1){
							msg = data.msg
							_x.show_alert_sh(msg,true)
						}else{
							msg = data.msg
							_x.show_alert_sh(msg,false)
						}
					}
				})
			}
		})

		$('#descBtn').click(function(){
			var descMsg = $('#descMsg textarea').val();
			var progress = $(this).data('progress');
			var userID = $(this).data('id');
			
			if(_x.isEmpty(descMsg)){
				_x.show_alert_sh('请输入反馈内容',false)
				return;
			}
			
				$.ajax({
					type:'get',
					url:'/admin/reviewUser',
					data:{
						userID:userID,
						progress:progress,
						descMsg:descMsg
					},
					success:function(data){
						if(data.code == 1){
							msg = data.msg
							_x.show_alert_sh(msg,true)
						}else{
							msg = data.msg
							_x.show_alert_sh(msg,false)
						}
					}
				})
		})
		
	})
		
		
	</script>
#end